﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace IESN.BaseForms
{
    /// <summary>
    /// 上下文类，用于携带当前各窗体信息
    /// </summary>
    public class AppContext
    {
        private FormCollection _formItems=new FormCollection();

        public AppContext()
        {
            
        }

        public void AddFormItem(string frmName,BaseFrm frm)
        {
            if (!_formItems.ContainsKey(frmName))
                _formItems.Add(frmName,frm);
        }

        /// <summary>
        /// 移除窗体
        /// </summary>
        /// <param name="frmName"></param>
        public void RemoveFormItem(string frmName)
        {
            if (_formItems.ContainsKey(frmName))
                _formItems.Remove(frmName);
        }

        //private LoginUserInfo _userInfo;
        ///// <summary>
        ///// 登入用户的信息
        ///// </summary>
        //public virtual LoginUserInfo UserInfo
        //{
        //    get { return _userInfo; }
        //}

        /// <summary>
        /// 根据名称来获取窗体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="formName"></param>
        /// <returns></returns>
        public BaseFrm GetForm(string formName)
        {
            if (_formItems.ContainsKey(formName))
            {
                BaseFrm frm = this._formItems[formName];
                return frm;
            }
            else
                return null;
        }

        /// <summary>
        /// 获取所有的模块接口
        /// </summary>
        /// <returns></returns>
        public ICollection<BaseFrm> GetModuleEnumerator()
        {
            return this._formItems.Values;
        }
    }
}
